<?php
namespace app\api\controller\zfcom;
use x\my\Captcha;
class Comcodeimg extends Base
{
	//获取验证码
    public function getcode()
    {
        $token = token();
        cookie('captcha_token',$token);
        $end_time = time()+c('type.expire_time');
        return suc(['img_token'=>$token,'url'=>url("/com/captcha")."?token=$token",'end_time'=>$end_time]);
    }


    /**
     * 验证图片验证码是否正确
     */
    public function checkCodeimg(){
        $d = $this->post;
        $rule = [
            'img_token'=>'require',
            'code'     =>'require',
        ];
        $msg = [];
        check($rule, $msg, $d);

        if( !Captcha::checkCaptcha($d['img_token'],$d['code']) ){
            err('验证码错误!');
        }else{
            $token = m('StepToken','xcom')->create();
            suc(['step_token'=>$token]);
        }
    }
}
